//
//  MTHomeOriginalView.swift
//  MTWeiBo
//
//  Created by user on 2017/7/26.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit
import SDWebImage
class MTHomeOriginalView: UIView {

    
    //数据模型(重写set方法)
    var statusViewModel: MTSatusViewModel? {
        didSet{
            //用户头像地址
            if let urlStr = statusViewModel?.status?.user?.profile_image_url {
                //显示头像
                userImageView.sd_setImage(with: URL(string: urlStr), placeholderImage: UIImage(named: "avatar_default_big"))
            }
            
            //昵称
            screenNameLabel.text = statusViewModel?.status?.user?.screen_name
            //微博内容
            contentLabel.text = statusViewModel?.status?.text
            //来源
           // sourceLabel.text = statusViewModel?.status?.source
            //会员等级图片
            mbrankImageView.image = statusViewModel?.mbrankImage
            //认证图片
            verifiedTypeImageView.image = statusViewModel?.verifiedTypeImage
            //来源
            sourceLabel.text = statusViewModel?.status?.source
        }
    }
    
    
    
    //  MARK: --懒加载控件
    //  用户头像
    fileprivate lazy var userImageView:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    //认证图片
    fileprivate lazy var verifiedTypeImageView:UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    //昵称
    fileprivate lazy var screenNameLabel:UILabel = {
        let label = UILabel(fontSize: 14, textColor: UIColor.darkGray)
        label.text = "搞笑趣闻"
        return label
    }()
    //时间
    fileprivate lazy var timeLabel:UILabel = {
       let label = UILabel(fontSize: 13, textColor: UIColor.orange)
        label.text = "刚刚"
        return label
    }()
    //来源
    fileprivate lazy var sourceLabel: UILabel = {
       let label = UILabel(fontSize: 12, textColor:UIColor.lightGray)
        label.text = "来自: ✨的你"
        return label
    }()
    //会员等级图片
    fileprivate lazy var mbrankImageView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    
    //微博内容
    fileprivate lazy var contentLabel: UILabel = {
        let label = UILabel(fontSize: 14, textColor: UIColor.darkGray)
        label.text = "同行的老外在深圳买了一把大弹簧刀放行李箱在普通安检的时候被查到，保安队长也是一脸嫌弃，“外国人携带管制刀具交给警察手续也很繁琐的！算你自己丢弃吧！”我说如果是我的就简单了呗，直接带走拘留"
        label.numberOfLines = 0
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        //backgroundColor = UIColor.blue
        //添加
        addSubview(userImageView)
        addSubview(verifiedTypeImageView)
        addSubview(screenNameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(mbrankImageView)
        addSubview(contentLabel)
        //约束
        userImageView.snp.makeConstraints { (make) in
            make.top.leading.equalTo(self).offset(HomeCellMargin)
            make.height.width.equalTo(35)
        }
        verifiedTypeImageView.snp.makeConstraints { (make) in
            make.centerX.equalTo(userImageView.snp.trailing)
            make.centerY.equalTo(userImageView.snp.bottom)
        }
        screenNameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(userImageView)
            make.leading.equalTo(userImageView.snp.trailing).offset(HomeCellMargin)
        }
        timeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(screenNameLabel.snp.bottom)
            make.leading.equalTo(screenNameLabel)
        }
        sourceLabel.snp.makeConstraints { (make) in
            make.top.equalTo(timeLabel)
            make.leading.equalTo(timeLabel.snp.trailing).offset(HomeCellMargin)
        }
        mbrankImageView.snp.makeConstraints { (make) in
            make.top.equalTo(screenNameLabel)
            make.leading.equalTo(screenNameLabel.snp.trailing).offset(HomeCellMargin)
        }
        contentLabel.snp.makeConstraints { (make) in
            make.top.equalTo(userImageView.snp.bottom).offset(HomeCellMargin)
            make.leading.equalTo(userImageView)
            make.trailing.equalTo(self).offset(-HomeCellMargin)
        }
        
        //重要约束
        self.snp.makeConstraints { (make) in
            make.bottom.equalTo(contentLabel).offset(HomeCellMargin)
        }
    }
}
